package com.cr.api.controller;

import com.cr.common.config.RuoYiConfig;
import com.cr.common.config.ServerConfig;
import com.cr.common.core.domain.AjaxResult;
import com.cr.common.utils.bean.MyBeanUtils;
import com.cr.common.utils.file.FileUploadUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@RestController
@RequestMapping("/api/common")
public class ApiCommonController {
                @Autowired
    /*     */   private ServerConfig serverConfig;
    /*     */   @PostMapping({"/upload"})
    /*     */   public AjaxResult uploadFile(MultipartFile file) throws Exception {
        /*     */     try {
            /*  81 */       String filePath = RuoYiConfig.getUploadPath();
            /*  83 */       String fileName = FileUploadUtils.upload(filePath, file);
            /*  84 */       String url = this.serverConfig.getUrl() + fileName;
            /*  85 */       AjaxResult ajax = AjaxResult.success();
            /*  86 */       ajax.put("fileName", fileName);
            /*  87 */       ajax.put("url", url);
            /*  88 */       ajax.put("name", file.getOriginalFilename());
            /*  89 */       return ajax;
            /*  91 */     } catch (Exception e) {
            /*  93 */       return AjaxResult.error(e.getMessage());
            /*     */     }
        /*     */   }
}
